/**
 * 作者: chenlingzhi
 * 日期: 2024-12-13 14:05:21
 * 备注: 用户成长基金数据
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class UserGrowthFundModel extends BaseModel implements Model {
	public static final String LISTKEY = "user_id.type";
	public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
	public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_QUEUE;// 数据入库类型 队列入库
	public static final boolean ORDER_LIST = false;// 是否需要额外的有序列表

	protected long id; // id
	protected long userId; // 用户id
	protected int type; // 基金类型
	protected byte isBuy1; // 是否购买第1档
	protected String freeReward1 = ""; // 第1档免费奖励领取
	protected String payReward1 = ""; // 第1档付费奖励领取
	protected byte isBuy2; // 是否购买第2档
	protected String freeReward2 = ""; // 第2档免费奖励领取
	protected String payReward2 = ""; // 第2档付费奖励领取
	protected byte isBuy3; // 是否购买第3档
	protected String freeReward3 = ""; // 第3档免费奖励领取
	protected String payReward3 = ""; // 第3档付费奖励领取

	public void reset() {
	}

	protected String getKey() {
		return "UserGrowthFund." + userId + "." + type;
	}

	protected String getListKey() {
		return "UserGrowthFund." + userId;
	}

	protected String getListItemKey() {
		return type + "";
	}

	public void doCreate() {
		setTableId();
		insert();
	}

	public void setTableId() {
		putId(incrTableId("user_growth_fund"));
	}

	public JsonObject insert() {
		return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
	}

	public void delete() {
		super.delete(getKey(), id, UPDATE_DB_TYPE, userId, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
	}

	/**
	 * 根据入库类型更新
	 */
	public JsonObject update() {
		return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, userId, getAllObj(), LISTKEY, getListKey(), getListItemKey());
	}

	/**
	 * 实时入队列
	 */
	public JsonObject updateQueueNow() {
		return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
	}

	public JsonObject getAllObj(){
		JsonObject obj = new JsonObject();
		obj.put("id", id); // id
		obj.put("userId", userId); // 用户id
		obj.put("type", type); // 基金类型
		obj.put("isBuy1", isBuy1); // 是否购买第1档
		obj.put("freeReward1", freeReward1); // 第1档免费奖励领取
		obj.put("payReward1", payReward1); // 第1档付费奖励领取
		obj.put("isBuy2", isBuy2); // 是否购买第2档
		obj.put("freeReward2", freeReward2); // 第2档免费奖励领取
		obj.put("payReward2", payReward2); // 第2档付费奖励领取
		obj.put("isBuy3", isBuy3); // 是否购买第3档
		obj.put("freeReward3", freeReward3); // 第3档免费奖励领取
		obj.put("payReward3", payReward3); // 第3档付费奖励领取
		return obj;
	}

	public long getId() {
		return id;
	}

	public void putId(long id) {
		if (this.id != id) {
			this.id = id;
			updateRedisHashField(getKey(), "id", this.id);
		}
	}

	public void addId(long value) {
		this.id += value;
		updateRedisHashField(getKey(), "id", this.id);
	}

	public long getUserId() {
		return userId;
	}

	public void putUserId(long userId) {
		if (this.userId != userId) {
			this.userId = userId;
			updateRedisHashField(getKey(), "userId", this.userId);
		}
	}

	public void addUserId(long value) {
		this.userId += value;
		updateRedisHashField(getKey(), "userId", this.userId);
	}

	public int getType() {
		return type;
	}

	public void putType(int type) {
		if (this.type != type) {
			this.type = type;
			updateRedisHashField(getKey(), "type", this.type);
		}
	}

	public void addType(int value) {
		this.type += value;
		updateRedisHashField(getKey(), "type", this.type);
	}

	public byte getIsBuy1() {
		return isBuy1;
	}

	public void putIsBuy1(byte isBuy1) {
		if (this.isBuy1 != isBuy1) {
			this.isBuy1 = isBuy1;
			updateRedisHashField(getKey(), "isBuy1", this.isBuy1);
		}
	}

	public void addIsBuy1(byte value) {
		this.isBuy1 += value;
		updateRedisHashField(getKey(), "isBuy1", this.isBuy1);
	}

	public JsonArray getFreeReward1Array() {
		if (this.freeReward1 != null && this.freeReward1.length() > 0) {
			return new JsonArray(this.freeReward1);
		} else {
			return new JsonArray();
		}
	}

	public String getFreeReward1() {
		return freeReward1;
	}

	public void putFreeReward1(String freeReward1) {
		if (!this.freeReward1.equals(freeReward1)) {
			this.freeReward1 = freeReward1;
			updateRedisHashField(getKey(), "freeReward1", this.freeReward1);
		}
	}

	public JsonArray getPayReward1Array() {
		if (this.payReward1 != null && this.payReward1.length() > 0) {
			return new JsonArray(this.payReward1);
		} else {
			return new JsonArray();
		}
	}

	public String getPayReward1() {
		return payReward1;
	}

	public void putPayReward1(String payReward1) {
		if (!this.payReward1.equals(payReward1)) {
			this.payReward1 = payReward1;
			updateRedisHashField(getKey(), "payReward1", this.payReward1);
		}
	}

	public byte getIsBuy2() {
		return isBuy2;
	}

	public void putIsBuy2(byte isBuy2) {
		if (this.isBuy2 != isBuy2) {
			this.isBuy2 = isBuy2;
			updateRedisHashField(getKey(), "isBuy2", this.isBuy2);
		}
	}

	public void addIsBuy2(byte value) {
		this.isBuy2 += value;
		updateRedisHashField(getKey(), "isBuy2", this.isBuy2);
	}

	public JsonArray getFreeReward2Array() {
		if (this.freeReward2 != null && this.freeReward2.length() > 0) {
			return new JsonArray(this.freeReward2);
		} else {
			return new JsonArray();
		}
	}

	public String getFreeReward2() {
		return freeReward2;
	}

	public void putFreeReward2(String freeReward2) {
		if (!this.freeReward2.equals(freeReward2)) {
			this.freeReward2 = freeReward2;
			updateRedisHashField(getKey(), "freeReward2", this.freeReward2);
		}
	}

	public JsonArray getPayReward2Array() {
		if (this.payReward2 != null && this.payReward2.length() > 0) {
			return new JsonArray(this.payReward2);
		} else {
			return new JsonArray();
		}
	}

	public String getPayReward2() {
		return payReward2;
	}

	public void putPayReward2(String payReward2) {
		if (!this.payReward2.equals(payReward2)) {
			this.payReward2 = payReward2;
			updateRedisHashField(getKey(), "payReward2", this.payReward2);
		}
	}

	public byte getIsBuy3() {
		return isBuy3;
	}

	public void putIsBuy3(byte isBuy3) {
		if (this.isBuy3 != isBuy3) {
			this.isBuy3 = isBuy3;
			updateRedisHashField(getKey(), "isBuy3", this.isBuy3);
		}
	}

	public void addIsBuy3(byte value) {
		this.isBuy3 += value;
		updateRedisHashField(getKey(), "isBuy3", this.isBuy3);
	}

	public JsonArray getFreeReward3Array() {
		if (this.freeReward3 != null && this.freeReward3.length() > 0) {
			return new JsonArray(this.freeReward3);
		} else {
			return new JsonArray();
		}
	}

	public String getFreeReward3() {
		return freeReward3;
	}

	public void putFreeReward3(String freeReward3) {
		if (!this.freeReward3.equals(freeReward3)) {
			this.freeReward3 = freeReward3;
			updateRedisHashField(getKey(), "freeReward3", this.freeReward3);
		}
	}

	public JsonArray getPayReward3Array() {
		if (this.payReward3 != null && this.payReward3.length() > 0) {
			return new JsonArray(this.payReward3);
		} else {
			return new JsonArray();
		}
	}

	public String getPayReward3() {
		return payReward3;
	}

	public void putPayReward3(String payReward3) {
		if (!this.payReward3.equals(payReward3)) {
			this.payReward3 = payReward3;
			updateRedisHashField(getKey(), "payReward3", this.payReward3);
		}
	}

}